package com.qigao.mall.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qigao.mall.api.AccountSerivce;
import com.qigao.mall.api.ChannelRouteService;
import com.qigao.mall.api.RefundService;
import com.qigao.mall.api.ShopEmpService;
import com.qigao.mall.channel.dto.ChannelRefundRespDto;
import com.qigao.mall.commons.dto.*;
import com.qigao.mall.commons.enums.*;
import com.qigao.mall.commons.exceptions.BusinessException;
import com.qigao.mall.commons.param.ChannelRespParam;
import com.qigao.mall.commons.param.CommonReqParam;
import com.qigao.mall.commons.utils.DateUtil;
import com.qigao.mall.commons.utils.IDUtils;
import com.qigao.mall.jdbc.mapper.*;
import com.qigao.mall.jdbc.model.*;
import com.qigao.mall.service.channel.ChannelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author luiz
 * @Title: com.qigao.mall.service.impl
 * @ProjectName three-mall
 * @date 2019-11-2019/11/21 13:38
 * @Description:退款服务
 */
@Service
@Slf4j
public class RefundServiceImpl implements RefundService {
    @Resource
    private TbRefundTotalMapper tbRefundTotalMapper;
    @Resource
    private TbOrderTotalMapper tbOrderTotalMapper;
    @Resource
    private TbRefundDetailMapper tbRefundDetailMapper;
    @Resource
    private TbPayDetailMapper tbPayDetailMapper;
    @Resource
    private ChannelService channelService;
    @Resource
    private ChannelRouteService channelRouteService;
    @Resource
    DataSourceTransactionManager transactionManager;
    @Resource
    private AccountSerivce accountSerivce;
    @Resource
    private ShopEmpService shopEmpService;

    @Override
    public Result applyRefund(RefundApplyDto refundApplyDto) {
        //状态检查
        String orderNo = refundApplyDto.getOrderNo();
        TbOrderTotal tbOrderTotal = tbOrderTotalMapper.selectByOrderNo(orderNo);
        if (tbOrderTotal == null || OrderStatusEnum.HAS_PAY.getCode() != tbOrderTotal.getOrderStatus()

        ) {
            log.warn("订单:{}的状态不是已收货状态，不能发起退款申请", orderNo);
            return Result.newError(ResultCode.OPER_NOT_ALlOWED);
        }
        BigDecimal applyRefundAmt=new BigDecimal(refundApplyDto.getRefundAmt());
        if(tbOrderTotal.getOrderAmt().compareTo(applyRefundAmt)<0){
            log.warn("退款金额不能超过订单{}总金额", orderNo);
            return Result.newError(ResultCode.OPER_NOT_ALlOWED.getCode(),"申请退款金额不能超过订单总额");
        }
        DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
        defaultTransactionDefinition.setName(TransactionTypeEnum.APPLY_REFUND.getCode());
        defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus transactionStatus = transactionManager.getTransaction(defaultTransactionDefinition);
        try {
            TbOrderTotal updateOrder = new TbOrderTotal();
            updateOrder.setOrderNo(tbOrderTotal.getOrderNo());
            updateOrder.setVersion(tbOrderTotal.getVersion());
            updateOrder.setOrderStatus(OrderStatusEnum.REFUND_PROC.getCode());
            tbOrderTotalMapper.updateOrderStatus(updateOrder);
            //入库
            TbRefundTotal tbRefundTotal = new TbRefundTotal();
            String refundOrderNo=IDUtils.genIdStr(IdTypeEnum.REFUND);
            tbRefundTotal.setRefundOrderNo(refundOrderNo);
            tbRefundTotal.setApplyRefundTime(new Date());
            tbRefundTotal.setApplyRefundUser(refundApplyDto.getUserNo());
            tbRefundTotal.setOperNo(refundApplyDto.getUserNo());
            tbRefundTotal.setGoodsStatus(refundApplyDto.getGoodsStatus());
            tbRefundTotal.setGoodsStatusDesc(refundApplyDto.getGoodsStatus());
            tbRefundTotal.setSellReason(refundApplyDto.getSellReason());
            tbRefundTotal.setSellReasonDesc(refundApplyDto.getSellReasonDesc());
            tbRefundTotal.setServiceType(refundApplyDto.getServiceType());
            tbRefundTotal.setServiceTypeDesc(refundApplyDto.getServiceTypeDesc());
            tbRefundTotal.setRefundReason(refundApplyDto.getRefundReason());
            tbRefundTotal.setOrderNo(refundApplyDto.getOrderNo());
            tbRefundTotal.setRefundAmt(new BigDecimal(refundApplyDto.getRefundAmt()));
            tbRefundTotal.setActRefundAmt(new BigDecimal(refundApplyDto.getRefundAmt()));
            tbRefundTotal.setOperStatus(RefundStatusEnum.REFUND_INIT.getCode());
            tbRefundTotal.setShopNo(tbOrderTotal.getShopNo());
            tbRefundTotalMapper.insertSelective(tbRefundTotal);
            transactionManager.commit(transactionStatus);
            log.info("对订单:{}进行退款申请成功!",orderNo);
            return Result.newSuccess(refundOrderNo);
        } catch (Exception e) {
            log.error("退款申请发生异常,事务回滚:{}", e);
            transactionManager.rollback(transactionStatus);
            return Result.newError(ResultCode.SAVE_DB_ERROR);
        }
    }

    @Override
    public Result<RefundOrderResultDto> findRefundByOrderNo(String orderNo) {
        TbRefundTotal tbRefundTotal=tbRefundTotalMapper.selectTopOneByOrderNo(orderNo);
        if(tbRefundTotal==null){
            return Result.newError(ResultCode.COMMON_DATA_NOT_EXISTS);
        }
        return Result.newSuccess(convertToDto(tbRefundTotal));
    }

    private RefundOrderResultDto convertToDto(TbRefundTotal tbRefundTotal) {
        RefundOrderResultDto refundOrderResultDto=new RefundOrderResultDto();
        BeanUtils.copyProperties(tbRefundTotal,refundOrderResultDto);
        refundOrderResultDto.setOperStatusDesc(RefundStatusEnum.parse(tbRefundTotal.getOperStatus()).getName());
        refundOrderResultDto.setApplyRefundTime(DateUtil.getDateTimeFormat(tbRefundTotal.getApplyRefundTime()));
        refundOrderResultDto.setOperTime(DateUtil.getDateTimeFormat(tbRefundTotal.getOperTime()));
        refundOrderResultDto.setRefundFinishTime(DateUtil.getDateTimeFormat(tbRefundTotal.getRefundFinishTime()));
        return refundOrderResultDto;
    }

    @Override
    public Result<PageInfo<RefundOrderResultDto>> findRefundList(RefundQueryDto refundQueryDto) {
        PageHelper.startPage(refundQueryDto.getPageNum(),refundQueryDto.getPageSize());
        Page<TbRefundTotal> tbRefundTotalPage=(Page<TbRefundTotal>)tbRefundTotalMapper.selectRefundList(refundQueryDto);
        if(tbRefundTotalPage.getResult()==null || tbRefundTotalPage.getResult().size()==0){
            return Result.newError(ResultCode.COMMON_DATA_NOT_EXISTS);
        }
        Page<RefundOrderResultDto> refundResultDtoPage=new Page<RefundOrderResultDto>();
        BeanUtils.copyProperties(tbRefundTotalPage,refundResultDtoPage);
        for(TbRefundTotal tbRefundTotal:tbRefundTotalPage.getResult()){
            refundResultDtoPage.add(convertToDto(tbRefundTotal));
        }
        return Result.newSuccess(new PageInfo<>(refundResultDtoPage));
    }

    @Override
    public Result refundAudit(RefundAuditDto refundAuditDto) {
        //审核通过 需要发起退款操作，拒绝则状态回退。
        Integer orderStatus=OrderStatusEnum.HAS_RECV.getCode();
        Integer refundStatus=RefundStatusEnum.REFUND_REJECT.getCode();
        String refundOrderNo=refundAuditDto.getRefundOrderNo();
        TbRefundTotal tbRefundTotal=tbRefundTotalMapper.selectByRefundOrderNo(refundOrderNo);
        if(tbRefundTotal==null){
            log.warn("退款单{},不存在", refundOrderNo);
            return Result.newError(ResultCode.COMMON_DATA_NOT_EXISTS);
        }
       /* boolean ifEmp=shopEmpService.ifShopEmp(tbRefundTotal.getShopNo(),refundAuditDto.getUserNo());
        if(!ifEmp){
            log.warn("退款单{},非本店员工{}不能操作", refundOrderNo,refundAuditDto.getUserNo());
            return Result.newError(ResultCode.OPER_NOT_ALlOWED.getCode(),"非本店员工不能操作");
        }*/
        if(RefundStatusEnum.REFUND_INIT.getCode()!=tbRefundTotal.getOperStatus()){
            log.warn("退款单状态不是待处理状态{}", refundOrderNo);
            return Result.newError(ResultCode.OPER_NOT_ALlOWED);
        }
        if(tbRefundTotal.getRefundAmt().compareTo(new BigDecimal(refundAuditDto.getActRefundAmt()))<0){
            log.warn("实际退款金额不能超过申请金额 {}", refundOrderNo);
            return Result.newError(ResultCode.OPER_NOT_ALlOWED.getCode(),"实际退款金额不能超过申请金额");
        }
        DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
        defaultTransactionDefinition.setName(TransactionTypeEnum.AUDIT_REFUND.getCode());
        defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus transactionStatus = transactionManager.getTransaction(defaultTransactionDefinition);
        try {
            TbRefundTotal updateRefund = new TbRefundTotal();
            updateRefund.setId(tbRefundTotal.getId());
            updateRefund.setOperDesc(refundAuditDto.getAuditDesc());
            updateRefund.setActRefundAmt(new BigDecimal(refundAuditDto.getActRefundAmt()));
            updateRefund.setOperTime(new Date());
            if(AuditActionEnum.REJECT.equals(refundAuditDto.getAuditActionEnum())){
                TbOrderTotal tbOrderTotal = tbOrderTotalMapper.selectByOrderNo(tbRefundTotal.getOrderNo());
                TbOrderTotal updateOrder = new TbOrderTotal();
                updateOrder.setOrderNo(tbOrderTotal.getOrderNo());
                updateOrder.setVersion(tbOrderTotal.getVersion());
                updateOrder.setOrderStatus(orderStatus);
                updateRefund.setOperStatus(refundStatus);
                tbRefundTotalMapper.updateByPrimaryKeySelective(updateRefund);
                tbOrderTotalMapper.updateOrderStatus(updateOrder);
                log.info("退款审核成功!{}",refundAuditDto);
                transactionManager.commit(transactionStatus);
            }
            if(AuditActionEnum.PASS.equals(refundAuditDto.getAuditActionEnum())){
                //发起退款请求
                List<TbPayDetail> tbPayDetails=tbPayDetailMapper.selectPayByOrderNo(tbRefundTotal.getOrderNo());
                if(tbPayDetails==null||tbPayDetails.size()==0){
                    log.error("订单号{}没有付款记录，请仔细验证数据。",tbRefundTotal.getOrderNo());
                    return Result.newError(ResultCode.OPER_NOT_ALlOWED);
                }
                //退款金额校验
                TbPayDetail tbPayDetail=tbPayDetails.get(0);
                TbMerChannel tbMerChannel=channelRouteService.findChannelRoute(tbPayDetail.getMerNo(),tbPayDetail.getWebSource(),tbPayDetail.getPayWay());
                TbRefundDetail tbRefundDetail=new TbRefundDetail();
                BeanUtils.copyProperties(tbMerChannel,tbRefundDetail);
                tbRefundDetail.setPaySeqNo(tbPayDetail.getPaySeqNo());
                tbRefundDetail.setOrderNo(tbPayDetail.getOrderNo());
                tbRefundDetail.setRefundOrderNo(refundOrderNo);
                tbRefundDetail.setMerNo(tbPayDetail.getMerNo());
                tbRefundDetail.setMerName(tbPayDetail.getMerName());
                tbRefundDetail.setRefundSeqNo(IDUtils.genIdStr(IdTypeEnum.REFUND_SEQ));
                tbRefundDetail.setRefundAmt(new BigDecimal(refundAuditDto.getActRefundAmt()));
                tbRefundDetail.setBuylerId(tbPayDetail.getBuylerId());
                tbRefundDetail.setBuylerName(tbPayDetail.getBuylerName());
                tbRefundDetail.setRefundStatus(RefundStatusEnum.REFUND_INIT.getCode());
                tbRefundDetail.setRefundDesc(refundAuditDto.getAuditDesc());
                tbRefundDetail.setStartTime(new Date());
                tbRefundTotalMapper.updateByPrimaryKeySelective(updateRefund);
                tbRefundDetailMapper.insertSelective(tbRefundDetail);
                transactionManager.commit(transactionStatus);
                MerChannelDto merChannelDto=buildMerchantDto(tbMerChannel,tbRefundDetail);
                CommonReqParam commonReqParam=buildCommonParam(tbPayDetail,tbRefundDetail);
                ChannelRespParam channelRespParam=channelService.channelProcess(merChannelDto,commonReqParam);
                log.info("退款审核发送到渠道端后返回:{}",channelRespParam);
                if(!ChannelCodeEnum.SUCCESS.getCode().equals(channelRespParam.getRespCode())){
                    return Result.newError(ResultCode.CHANNEL_ERROR.getCode(),channelRespParam.getRespMsg());
                }else{
                    //不做更新处理，等待异步通知...
                    ChannelRefundRespDto channelRefundRespDto = JSON.parseObject(channelRespParam.getRespContent(), ChannelRefundRespDto.class);
                    channelRefundRespDto.setInnerRefundNo(tbRefundDetail.getRefundSeqNo());
                    if(YesNoEnum.YES.equals(channelRefundRespDto.getIfSyn())){
                        processNotifyOrder(channelRefundRespDto);
                    }

                }
            }
            return Result.newSuccess();
        }catch (Exception e){
            log.error("退款申请发生异常,事务回滚:{}{}", refundAuditDto,e);
            transactionManager.rollback(transactionStatus);
            return Result.newError(ResultCode.SAVE_DB_ERROR);
        }
    }

    @Override
    public List<TbRefundDetail> findUnRefundList() {
        return tbRefundDetailMapper.selectUnRefundList();
    }

    @Override
    public void retryQueryRefund(TbRefundDetail tbRefundDetail) {
        //2.查询支付通道
        TbMerChannel tbMerChannel=channelRouteService.findChannelRoute(tbRefundDetail.getMerNo(),tbRefundDetail.getWebSource(),tbRefundDetail.getPayWay());
        MerChannelDto merChannelDto=buildMerchantDto(tbMerChannel,tbRefundDetail);
        merChannelDto.setChannelAction(ChannelActionEnum.REFUND_QUERY.getCode());
        CommonReqParam commonReqParam=new CommonReqParam();
        ChannelRespParam channelRespParam=channelService.channelProcess(merChannelDto,commonReqParam);
        TbRefundDetail updateRefundDetail=new TbRefundDetail();
        updateRefundDetail.setId(tbRefundDetail.getId());
        tbRefundDetailMapper.updateRetry(updateRefundDetail);
        if(ChannelCodeEnum.SUCCESS.getCode().equals(channelRespParam.getRespCode())){
            ChannelRefundRespDto channelRefundRespDto =JSON.parseObject(channelRespParam.getRespContent(), ChannelRefundRespDto.class);
            //同步更新订单状态
            processNotifyOrder(channelRefundRespDto);
        }
    }

    @Override
    public void processNotifyOrder(ChannelRefundRespDto channelRefundRespDto) {
        log.info("需要处理的退款数据:{}", channelRefundRespDto);
        if(channelRefundRespDto.getRefundStatus()==null){
            log.warn("退款单状态不正确:{}", channelRefundRespDto);
        }
        TbRefundDetail tbRefundDetail=tbRefundDetailMapper.selectByRefundSeqNo(channelRefundRespDto.getInnerRefundNo());
        if(tbRefundDetail==null || RefundStatusEnum.REFUND_INIT.getCode()!=tbRefundDetail.getRefundStatus()){
            log.warn("退款单不存在或已经处理完成，无需再次处理:{}", channelRefundRespDto);
            return;
        }
        DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
        defaultTransactionDefinition.setName(TransactionTypeEnum.REFUND_NOTIFY.getCode());
        defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus transactionStatus = transactionManager.getTransaction(defaultTransactionDefinition);
        try{
            //更新退款明细
            Integer refundStatus= channelRefundRespDto.getRefundStatus().getCode();
            TbRefundDetail updateRefundDetail=new TbRefundDetail();
            updateRefundDetail.setRefundOrderNo(tbRefundDetail.getRefundOrderNo());
            updateRefundDetail.setRefundSeqNo(channelRefundRespDto.getInnerRefundNo());
            updateRefundDetail.setVersion(tbRefundDetail.getVersion());
            updateRefundDetail.setRefundStatus(refundStatus);
            updateRefundDetail.setRespRefundNo(channelRefundRespDto.getThirdRefundNo());
            updateRefundDetail.setRetCode(channelRefundRespDto.getRetCode());
            updateRefundDetail.setRetDesc(channelRefundRespDto.getRetMsg());
            updateRefundDetail.setRefundSuccessTime(channelRefundRespDto.getRefundSuccessDate());
            updateRefundDetail.setBuyRefundAmt(channelRefundRespDto.getRefundAmt());
            //更新退款总表
            TbRefundTotal tbRefundTotal=new TbRefundTotal();
            tbRefundTotal.setRefundOrderNo(tbRefundDetail.getRefundOrderNo());
            tbRefundTotal.setOperStatus(refundStatus);
            tbRefundTotal.setRefundFinishTime(new Date());
            if(refundStatus==RefundStatusEnum.REFUND_SUCCESS.getCode()){
                //更新订单表
                TbOrderTotal tbOrderTotal=new TbOrderTotal();
                tbOrderTotal.setOrderNo(tbRefundDetail.getOrderNo());
                tbOrderTotal.setOrderStatus(OrderStatusEnum.CLOSE.getCode());
                tbOrderTotal.setRefundAmt(channelRefundRespDto.getRefundAmt());
                //更新支付明细表
                TbPayDetail tbPayDetail=tbPayDetailMapper.selectByPaySeqNo(tbRefundDetail.getPaySeqNo());
                TbPayDetail updatePayDetail=new TbPayDetail();
                updatePayDetail.setId(tbPayDetail.getId());
                updatePayDetail.setVersion(tbPayDetail.getVersion());
                BigDecimal hasRefundAmt=tbPayDetail.getRefundSuccessAmt()==null?BigDecimal.ZERO:tbPayDetail.getRefundSuccessAmt();
                BigDecimal totalRefundAmt=hasRefundAmt.add(channelRefundRespDto.getRefundAmt());
                updatePayDetail.setRefundSuccessAmt(totalRefundAmt);
                if(tbPayDetail.getPayAmt().compareTo(totalRefundAmt)==0){
                    updatePayDetail.setPayStatus(PayStatusEnum.PAY_CLOSE.getCode());
                    updatePayDetail.setRetDesc("已全额退款");
                }
                tbOrderTotalMapper.updateByOrderNo(tbOrderTotal);
                tbPayDetailMapper.updateStatus(updatePayDetail);
                //添加账户余额、记录账户日志、记录账户交易日志
               /* AccountOperDto accountOperDto =new AccountOperDto();
                accountOperDto.setMerNo(tbPayDetail.getMerNo());
                accountOperDto.setUserNo(tbPayDetail.getBuylerId());
                accountOperDto.setSourceOrderNo(updateRefundDetail.getRefundSeqNo());
                accountOperDto.setSourceTradeType(TradeTypeEnum.REFUND);
                accountOperDto.setTradeAmt(updateRefundDetail.getBuyRefundAmt());
                accountSerivce.trade(accountOperDto);*/
            }
            tbRefundDetailMapper.updateStatus(updateRefundDetail);
            tbRefundTotalMapper.updateStatus(tbRefundTotal);

            transactionManager.commit(transactionStatus);
            log.info("退款单号:{}订单号：{}处理退款成功", channelRefundRespDto.getInnerRefundNo(),tbRefundDetail.getOrderNo());
        }catch (Exception e) {
            log.error("[退款通知]发生异常,事物回滚:{}",  e);
            transactionManager.rollback(transactionStatus);
            throw new BusinessException(ResultCode.SAVE_DB_ERROR.getCode(), ResultCode.SAVE_DB_ERROR.getMessage());
        }
    }

    /**
     * 系统自动退款
     * @param orderNo
     * @param payAmt
     */
    @Override
    public void autoRefund(String orderNo, BigDecimal payAmt) {
        RefundApplyDto refundApplyDto=new RefundApplyDto();
        refundApplyDto.setOrderNo(orderNo);
        refundApplyDto.setRefundAmt(payAmt.toString());
        refundApplyDto.setRefundReason("系统自动退款");
        Result applyResult=applyRefund(refundApplyDto);
        RefundAuditDto refundAuditDto=new RefundAuditDto();
        refundAuditDto.setAuditActionEnum(AuditActionEnum.PASS);
        refundAuditDto.setActRefundAmt(payAmt.toString());
        refundAuditDto.setRefundOrderNo((String)applyResult.getData());
        refundAuditDto.setAuditDesc("系统自动退款审核");
        refundAudit(refundAuditDto);
    }



    private CommonReqParam buildCommonParam(TbPayDetail tbPayDetail, TbRefundDetail tbRefundDetail) {
        CommonReqParam commonReqParam= new CommonReqParam();
        commonReqParam.setMerNo(tbPayDetail.getMerNo());
        commonReqParam.setCharsetCode("UTF-8");
        commonReqParam.setRequestTime(DateUtil.getDateTimeFormat(new Date()));
        commonReqParam.setServiceName("");// todo
        commonReqParam.setTermIp(tbPayDetail.getEquipIp());
        JSONObject reqContent=new JSONObject();
        BigDecimal payAmt=tbPayDetail.getPayAmt();
        reqContent.put("payAmt",payAmt);
        BigDecimal payAmtFen=tbPayDetail.getPayAmt().multiply(new BigDecimal(100));
        reqContent.put("payAmtFen",payAmtFen.longValue());
        BigDecimal refundAmt=tbRefundDetail.getRefundAmt();
        reqContent.put("refundAmt",refundAmt);
        BigDecimal refundAmtFen=tbRefundDetail.getRefundAmt().multiply(new BigDecimal(100));
        reqContent.put("refundAmtFen",refundAmtFen.longValue());
        commonReqParam.setReqContent(reqContent.toString());
        return commonReqParam;
    }

    private MerChannelDto buildMerchantDto(TbMerChannel tbMerChannel,TbRefundDetail tbRefundDetail) {
        MerChannelDto merChannelDto=new MerChannelDto();
        merChannelDto.setChannelAction(ChannelActionEnum.REFUND.getCode());
        merChannelDto.setProductNo(tbRefundDetail.getPayWay());
        merChannelDto.setProductName(tbRefundDetail.getPayWayName());
        merChannelDto.setChannelCode(tbMerChannel.getChannelCode());
        merChannelDto.setAppId(tbMerChannel.getAppId());
        merChannelDto.setSignType(tbMerChannel.getSignType());
        merChannelDto.setAppSecret(tbMerChannel.getAppSecret());
        merChannelDto.setPubKey(tbMerChannel.getPubKey());
        merChannelDto.setPrivKey(tbMerChannel.getPrivKey());
        merChannelDto.setResvKey(tbMerChannel.getResvKey());
        merChannelDto.setMd5Key(tbMerChannel.getMd5Key());
        merChannelDto.setChannelPartenerNo(tbRefundDetail.getChannelPartenerNo());
        merChannelDto.setInnerSeqNo(tbRefundDetail.getPaySeqNo());
        merChannelDto.setInnerRefundSeqNo(tbRefundDetail.getRefundSeqNo());
        return merChannelDto;
    }
}
